package org.jili.novoland.game;

import org.jili.novoland.base.Actor;
import org.jili.novoland.base.TiledLayer;

import android.graphics.Bitmap;

public class BattleMap extends TiledLayer implements Actor {
    public final static int FIELD_CLASS = 1;
    public final static int FIELD_ROCK = 2;
    public final static int FIELD_WATER = 3;
    public final static int FIELD_TREE = 4;

    public final static int TILE_WIDTH = 48;
    public final static int TILE_HEIGHT = 48;
    
    public final static int DIRECT_EAST = 0;
    public final static int DIRECT_SOUTH = 1;
    public final static int DIRECT_WEST = 2;
    public final static int DIRECT_NORTH = 3;

    private int sceneWidth, sceneHeight;

    public void setSceneSize(int sceneWidht, int sceneHeight) {
        if (sceneWidht <= 0 || sceneHeight <= 0)
            throw new IllegalArgumentException();

        this.sceneHeight = sceneHeight;
        this.sceneWidth = sceneWidht;

    }

    public BattleMap(int cols, int rows, Bitmap img) {
        super(cols, rows, img, TILE_HEIGHT, TILE_WIDTH);

    }

    @Override
    public void move(int dx, int dy) {
        int cx = getX();
        int cy = getY();
        int mapWitdh = getColumns() * TILE_WIDTH;
        int mapHeight = getRows() * TILE_HEIGHT;

        if (mapWitdh < sceneWidth)
            dx = (sceneWidth - mapWitdh) / 2 - cx;
        else {
            if (cx + dx > TILE_WIDTH)
                dx = TILE_WIDTH - cx;
            if (cx + dx + mapWitdh < sceneWidth - TILE_WIDTH)
                dx = sceneWidth - TILE_WIDTH - mapWitdh - cx;

        }
        if (mapHeight < sceneHeight)
            dy = (sceneHeight - mapHeight) / 2 - cy;
        else {
            if (cy + dy > TILE_HEIGHT)
                dy = TILE_HEIGHT - cy;

            if (cy + dy + mapHeight < sceneHeight - TILE_HEIGHT)
                dy = sceneHeight - TILE_HEIGHT - mapHeight - cy;
        }
        super.move(dx, dy);

    }

    public void tick() {
        // TODO Auto-generated method stub

    }

}
